import { reactive } from "vue";
import { getListApi as getAllPaymentApi } from "@/api/configCenter/paymentManagement";
import { getAllCompanyApi, getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
// import { getListApi as getCustomerApi } from "@/api/managementCenter/customerManagement";
import { getAllCustomerApi } from "@/api/common";
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  // {
  //   type: "input",
  //   label: "客户简称",
  //   keyName: "customerNames",
  //   placeholder: "支持批量(空格/逗号隔开)"
  // },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getAllCustomerApi,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  // {
  //   type: "select",
  //   label: "审批状态",
  //   keyName: "state",
  //   optConfig: {
  //     label: "name",
  //     value: "code"
  //   },
  //   options: [
  //     {
  //       name: "待审批",
  //       code: 3
  //     },
  //     {
  //       name: "审批通过",
  //       code: 5
  //     }
  //   ]
  // },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "财务",
    keyName: "finIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "6", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "账期",
    keyName: "accountPeriodIdList",
    optionsRequest: getAllPaymentApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "accountName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "input",
    label: "客户名称",
    keyName: "companyNames",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "datetimerange",
    label: "拣货时间",
    keyName: "depositTime"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  })
];

export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50"
  },
  {
    field: "customerName",
    title: "客户简称",
    minWidth: "120",
    sortable: true
  },
  {
    field: "authCompanyName",
    title: "客户名称",
    minWidth: "120"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "160",
    renderSlot: "waybillNum"
  },
  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "135",
    formatter: "formatDate",
    sortable: true
  },
  {
    field: "channelName",
    title: "预报渠道",
    minWidth: "140",
    sortable: true
  },
  {
    field: "itemNumber",
    title: "件数",
    minWidth: "80"
  },
  {
    field: "squaresNumber",
    title: "方数",
    minWidth: "80"
  },
  {
    field: "settlementWeight",
    title: "结算重",
    minWidth: "90"
  },
  {
    field: "receivablePrice",
    title: "应收金额",
    minWidth: "90"
  },
  {
    field: "declaredValue",
    title: "申报价值",
    minWidth: "100"
  },
  {
    field: "accountName",
    title: "账期",
    minWidth: "100"
  },
  {
    field: "bizName",
    title: "业务员",
    minWidth: "80",
    sortable: true
  },
  {
    field: "followName",
    title: "跟单员",
    minWidth: "80",
    sortable: true
  },
  {
    field: "finName",
    title: "财务",
    minWidth: "80",
    sortable: true
  },
  {
    field: "approvalName",
    title: "审批人",
    minWidth: "80"
  },
  // {
  //   field: "state",
  //   title: "审批状态",
  //   minWidth: "90",
  //   renderSlot: "state"
  // },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "100",
    sortable: true
  },
  {
    field: "approvalTime",
    title: "审批时间",
    minWidth: "140",
    fixed: "right",
    formatter: "formatDate"
  }
];
// 统计
export const statisticsColumn: Array<{ field: string; label: string }> = [
  {
    label: "票数",
    field: "ticketNumber"
  },
  {
    label: "件数",
    field: "itemNumber"
  },
  {
    label: "应收合计金额",
    field: "receivableTotalPrice"
  }
];
